package com.gec.shop;
import java.lang.Object;
import java.io.Serializable;
import java.util.Scanner;

public class Member implements Serializable {

    private int id;//会员id
    private  String password;//会员密码
    private  String name;//会员名称
    private  String sex;//会员性别
    private  long phone;//会员手机号
    private  double balance;//会员余额

    public Member() {
    }
    public Member(int id,String password,String name,String sex,long phone,double balance) {
        this.id = id;
        this.password = password;
        this.name = name;
        this.sex = sex;
        this.phone = phone;
        this.balance = balance;
    }

    public static Object memberRegister(Scanner scanner) {
        Member member = new Member();
        while(true){
            try {
                member.setBalance(0);
                System.out.println("请输入注册密码->");
                member.setPassword(scanner.next());
                System.out.println("请输入姓名->");
                member.setName(scanner.next());
                System.out.println("请输入性别->");
                member.setSex(scanner.next());
                System.out.println("请输入手机号(11位)->");
                String phone = scanner.next();
                if (phone.length() == 11) {
                    member.setPhone(Long.parseLong(phone));
                    return member;
                } else {
                    System.out.println("手机号格式不正确!");
                }
            }catch (Exception e){
                System.out.println("注册格式不正确!!!");
            }
        }
    }
    public static Member memberLogin(Scanner scanner){
        Member member = new Member();

        while(true){
            try {
                System.out.print("请输入登录ID->");
                member.setId(scanner.nextInt());
                System.out.print("请输入密码->");
                member.setPassword(scanner.next());
                return member;
            }catch (Exception e){
                System.out.println("请输入正确的格式!!!");
                scanner.next();
            }
        }
    }
    public static Member addbalance(Scanner scanner){
        Member member = new Member();
        while(true){
            try {
                System.out.print("请输入充值金额->");
                member.setBalance(scanner.nextDouble());
                return member;
            }catch (Exception e){
                System.out.println("请输入正确的格式!!!");
                scanner.nextDouble();
            }
        }
    }
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public long getPhone() {
        return phone;
    }

    public void setPhone(long phone) {
        this.phone = phone;
    }

    public double getBalance() {
        return balance;
    }

    public  void setBalance(double balance) {
        this.balance = balance;
    }

    @Override
    public String toString() {
        return "Member{" +
                "id=" + id +
                ", password='" + password + '\'' +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", phone=" + phone +
                ", balance=" + balance +
                '}';
    }
}
